package com.atwy.common.seatatcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@LocalTCC
public interface StorageServiceTCCApi {

    @PostMapping("/deductStorage")
    @TwoPhaseBusinessAction(name = "storageServiceTCCApi",commitMethod = "commit",rollbackMethod = "rollback")
    boolean prepare(@RequestBody BusinessActionContext businessActionContext,
                    @RequestParam("commodityCode") @BusinessActionContextParameter(paramName = "commodityCode") String commodityCode,
                    @RequestParam("count") @BusinessActionContextParameter(paramName = "count") int count);

    @PostMapping("/commit")
    boolean commit(@RequestBody BusinessActionContext businessActionContext);

    @PostMapping("/rollback")
    boolean rollback(@RequestBody BusinessActionContext businessActionContext);
}
